package com.michaelli.androidmoneyrecord.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	public static final int DB_VERSION = 1;
	public static final String DB_NAME = "MoneyRecord.db";

	public DBHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String userTableSql = "CREATE TABLE 'user' (" + "'_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
				+ "'name' TEXT NOT NULL," + "'passwd' TEXT NOT NULL DEFAULT (123456),"
				+ "'sex' INTEGER NOT NULL DEFAULT (1)," + "'email' TEXT)";
		db.execSQL(userTableSql);
		String feeTypeTableSql = "CREATE TABLE 'feetype' (" + "'_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
				+ "'name' TEXT NOT NULL," + "'user_id' INTEGER NOT NULL," + "'isInput' INTEGER NOT NULL DEFAULT (1))";
		db.execSQL(feeTypeTableSql);
		String recordTableSql = "CREATE TABLE 'record' (" + "'_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
				+ "'fee_type_id' INTEGER NOT NULL," + "'money' REAL NOT NULL," + "'user_id' INTEGER NOT NULL,"
				+ "'date_time' REAL," + "'note' TEXT)";
		db.execSQL(recordTableSql);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists user");
		db.execSQL("drop table if exists feetype");
		db.execSQL("drop table if exists record");
	}

}
